package cn.edu.gduf.luowowo.flight.service.impl;

import cn.edu.gduf.luowowo.flight.domain.FlightOrder;
import cn.edu.gduf.luowowo.flight.mapper.FlightOrderMapper;
import cn.edu.gduf.luowowo.flight.service.IFlightOrderService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

@Service
public class FlightOrderServiceImpl implements IFlightOrderService {
    @Autowired
    private FlightOrderMapper flightOrderMapper;

    @Override
    public void generateOrModifyOrder(FlightOrder order) {
        if (order.getId() == null){
            //生成新的订单
            //订单生成时间,解决订单中没有航班id的问题
            order.setOrderTime(new Date());
            flightOrderMapper.insert(order);
        } else {
            //修改原有订单
            flightOrderMapper.updateByPrimaryKey(order);
        }
    }

    @Override
    public List<FlightOrder> getFlightOrdersByUserId(Long userId) {
        return flightOrderMapper.selectByUserId(userId);
    }
}
